//
//  Receipt.m
//  Gekko
//
//  Created by jose on 06/06/13.
//  Copyright (c) 2013 Jose Luis Lopez. All rights reserved.
//

#import "Receipt.h"

@implementation Receipt

@synthesize userId, idi, date, totalAmount, taxAmount1, taxRate1, taxAmount2, taxRate2, taxAmount3, taxRate3, costType, description, status, image;

static Receipt *sharedReceipt = NULL;

+ (Receipt *)sharedReceipt {
    
    if (!sharedReceipt || sharedReceipt == NULL) {
        
        sharedReceipt = [[Receipt alloc] init];
    }
    
    return sharedReceipt;
}

+ (void)resetSharedReceipt {
    
    sharedReceipt = NULL;
}

+(void)setSharedReceipt:(Receipt *)receipt {
    
    sharedReceipt = receipt;
}

-(id)init {
    
    if (self = [super init]) {
        
        userId = [[NSUserDefaults standardUserDefaults] valueForKey:kKeyUserId]; //Current user
        
        idi = [NSString stringWithFormat:@"%d", arc4random()];
        date = [NSDate date];
        totalAmount = @"";
        taxAmount1 = @"";
        taxRate1 = @"21 %";
        taxAmount2 = @"";
        taxRate2 = @"";
        taxAmount3 = @"";
        taxRate3 = @"";
        costType = @"";
        description = @"";
        status = kStatusDraft;
        image = nil;
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {

    [coder encodeObject:userId forKey:@"userId"];
    [coder encodeObject:idi forKey:@"idi"];
    [coder encodeObject:date forKey:@"date"];
    [coder encodeObject:totalAmount forKey:@"totalAmount"];
    [coder encodeObject:taxAmount1 forKey:@"taxAmount1"];
    [coder encodeObject:taxRate1 forKey:@"taxRate1"];
    [coder encodeObject:taxAmount2 forKey:@"taxAmount2"];
    [coder encodeObject:taxRate2 forKey:@"taxRate2"];
    [coder encodeObject:taxAmount3 forKey:@"taxAmount3"];
    [coder encodeObject:taxRate3 forKey:@"taxRate3"];
    [coder encodeObject:costType forKey:@"costType"];
    [coder encodeObject:description forKey:@"description"];
    [coder encodeObject:status forKey:@"status"];
    [coder encodeObject:image forKey:@"image"];
}

- (id)initWithCoder:(NSCoder *)coder {
    
    if (self = [super init])
    {
        userId = [coder decodeObjectForKey:@"userId"];
        idi = [coder decodeObjectForKey:@"idi"];
        date = [coder decodeObjectForKey:@"date"];
        totalAmount = [coder decodeObjectForKey:@"totalAmount"];
        taxAmount1 = [coder decodeObjectForKey:@"taxAmount1"];
        taxRate1 = [coder decodeObjectForKey:@"taxRate1"];
        taxAmount2 = [coder decodeObjectForKey:@"taxAmount2"];
        taxRate2 = [coder decodeObjectForKey:@"taxRate2"];
        taxAmount3 = [coder decodeObjectForKey:@"taxAmount3"];
        taxRate3 = [coder decodeObjectForKey:@"taxRate3"];
        costType = [coder decodeObjectForKey:@"costType"];
        description = [coder decodeObjectForKey:@"description"];
        status = [coder decodeObjectForKey:@"status"];
        image = [coder decodeObjectForKey:@"image"];

    }
    return self;
}
@end
